
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<div id="materialTab" class="tab-pane">
	<div class="panel-body" style="padding-bottom: 0px; border-bottom: 0px;">

		<div class="col-lg-12 text-right" style="padding-right: 0px;">
			<button id="createMaterielButton" class="btn btn-sm" type="button" ><i class="fa fa-plus"></i>&nbsp;&nbsp;<span class="bold">生成物料需求</span></button>
			<button id="getMaterielButton" class="btn btn-info btn-sm" type="button" ><i class="fa fa-calendar-plus-o"></i>&nbsp;&nbsp;<span class="bold">领料</span></button>
			<button id="returnMaterielButton" class="btn btn-warning btn-sm" type="button" ><i class="fa fa-calendar-times-o"></i>&nbsp;&nbsp;<span class="bold">退料</span></button>
			<%-- 
			<button id="searchButton" class="btn btn-default btn-sm" type="button"><i class="fa fa-search"></i>&nbsp;&nbsp;展开查询</button>
			--%>
		</div><br/>

		<div class="table-responsive">
			<table class="table table-stripped table-hover table-bordered border-top">

				<thead>
					<tr>
						<th width="5%">序号</th>
						<th>顺序</th>
						<th>工序</th>
						<th>物料</th>
						<th>规格</th>
						<th>单位</th>
						<th>所需数量</th>
						<th>领用数量</th>
						<th>退回数量</th>
						<th>前置期（天）</th>
						<th width="5%">状态</th>
						<th width="10%">操作</th>
					</tr>
				</thead>
				<tbody>
					
					<c:forEach items="${requestScope.prodWipTaskMaterialList}" var="data" varStatus="status">
					<tr>
						<td>${status.count}</td>
						<td>${data.orderNumber}</td>
						<td>${data.procedureName}</td>
						<td>${data.materialName}</td>
						<td>${data.materialStandard}</td>
						<td>${data.materialUnit}</td>
						<td class="quantity">${data.quantity}</td>
						<td class="getQuantity">${data.getQuantity}</td>
						<td class="returnQuantity">${data.returnQuantity}</td>
						<td>${data.producePreDays}</td>
						<td>
						<c:choose>
						   <c:when test="${data.status=='Y'}">
						       <span class="label label-primary">有效</span>
						   </c:when>
						   <c:otherwise>
						       <span class="label label-danger">无效</span>
						   </c:otherwise>
						</c:choose>
						</td>
						<td>
							<div class="btn-group">
								<button class=" btn btn-xs btn-redragon-adjust" onclick="openInvOutput('${param.taskCode}')"><i class="fa fa-navicon"></i>&nbsp;领料单</button>&nbsp;
								<button class=" btn btn-xs btn-redragon-adjust" onclick="openInvInput('${param.taskCode}')"><i class="fa fa-navicon"></i>&nbsp;退料单</button>&nbsp;
							</div>
						</td>
					</tr>
					</c:forEach>
					
				</tbody>
				<tfoot>
					<%-- 导入页码 --%>
					<jsp:include page="../../common/pages.jsp"></jsp:include>
				</tfoot>
			</table>

		</div>

	</div>
</div>

<div id="addLineModal"></div>

<script>
	$(document).ready(function() {
		$("#createMaterielButton").click(function(){
			var alertText = "确认生成物料需求？";
			if($("#materialTab tbody tr").length>1){
				alertText = "确认重新生成物料需求？原来的需求数据将被清空";
			}
			
			redragonJS.confirm(alertText, function(){
				createMateriel();
			});
		});
		
		$("#searchButton").click(function(){
		    if($("#searchDiv").css("display")=="none"){
		        $("#searchDiv").show();
		        $("#searchButton").html('<i class="fa fa-search"></i>&nbsp;&nbsp;关闭查询');
		        $("#searchButton").addClass("btn-outline btn-warning");
		        $("#searchButton").blur();
		    }else{
		        $("#searchDiv").hide();
		        $("#searchButton").html('<i class="fa fa-search"></i>&nbsp;&nbsp;展开查询');
		        $("#searchButton").removeClass("btn-outline btn-warning");
		        $("#searchButton").blur();
		    }
		});
		
		//领用物料
		$("#getMaterielButton").click(function(){
			window.open("web/invOutputHead/getInvOutputHead?taskCode=${param.taskCode}");
		});
		
		//退料
		$("#returnMaterielButton").click(function(){
			window.open("web/invInputHead/getInvInputHead?taskCode=${param.taskCode}");
		});
	});
	
	function openInvInput(code){
		window.open("web/invInputHead/getInvInputHeadList?inputSourceType=PROD&inputSourceHeadCode="+code+"&inputType=PROD_RETURN");
	}
	
	function openInvOutput(code){
		window.open("web/invOutputHead/getInvOutputHeadList?outputSourceType=PROD&outputSourceHeadCode="+code+"&outputType=PROD_GET");
	}
	
	/*
	function editSysUser(id){
		getAddLineModal(id);
	}
	
	function deleteSysUser(id) {
		redragonJS.confirm("确认删除数据？", function(){
			deleteLine(id);
		});
	}
	
	function getAddLineModal(id){
		$.ajax({
			type: "post",
			url: "web/prodWorkCraftProcedure/getProdWorkCraftProcedure",
			data: {"craftProcedureId": id, "craftCode": "${param.craftCode}"},
			async: false,
			dataType: "html",
			cache: false,
			success: function(data){
				if(data!=""){
					$("#addLineModal").html(data);
					$('#addLineDiv').modal('show');
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				redragonJS.alert(textStatus);
			}
		});
	}
	
	function deleteLine(id){
		$.ajax({
			type: "post",
			url: "web/prodWorkCraftProcedure/deleteProdWorkCraftProcedure",
			data: {"craftProcedureId": id, "craftCode": "${param.craftCode}"},
			async: false,
			dataType: "html",
			cache: false,
			success: function(data){
				var json = JSON.parse(data);
				if(json.result=="success"){
					redragonJS.close();
					getLineTab("${param.craftCode}");
				}else{
					redragonJS.alert("删除工序行错误");
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				redragonJS.alert(textStatus);
			}
		});
	}
	*/
	
	function createMateriel(){
		redragonJS.loading("line-ibox-content");
		
		$.ajax({
			type: "post",
			url: "web/prodWipTaskMaterial/createWipTaskMaterielAjax",
			data: {"taskCode": "${param.taskCode}"},
			async: true,
			dataType: "json",
			cache: false,
			success: function(data){
				redragonJS.removeLoading("line-ibox-content");
				if(data.result=="success"){
					redragonJS.close();
					getMaterialLineTab("${param.taskCode}");
				}else if(data.result=="hint"){
					redragonJS.alert(data.message);
				}else{
					redragonJS.alert("创建物料需求错误");
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				redragonJS.alert(textStatus);
			}
		});
	}
</script> 